package com.zjw.core.reflect;


import java.lang.reflect.Field;

/**
 * 修改对象的私有常量值
 * */
public class ReflectPrivateFinalPropertyExample {

    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        Son son = new Son();
        Class sonClass = Son.class;

        Field field = sonClass.getDeclaredField("LIFE_GOAL");

        if(field != null){
            System.out.println("修改之前的值是:"+ son.getLIFE_GOAL());
            field.setAccessible(true);

            field.set(son,"活着走出2020");

            System.out.println("修改之后的值是:"+son.getLIFE_GOAL());

            if("财富自由".equals(son.getLIFE_GOAL())){
                System.out.println("天不绝我，我必发财");
            }
        }
    }
}
